<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />

    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>
    <ex_super_dialog_form ref="formDialog" v-bind="edit_dialog" @afterSubmitSuccess="$refs['SuperTablePage'].reload()">
      <template v-slot:orderNo="{ formData }">
        <el-form-item label="订单编号" prop="orderNo" class="form_item_default">
          <el-select v-model="formData.orderNo" @change="orderNoChange" class="form_input_default" filterable
            placeholder="请输入订单编号">
            <el-option v-for="(item, index) in orderNoData" :key="index" :label="item.trackNumber"
              :value="item.trackNumber"></el-option>
          </el-select>
        </el-form-item>
      </template>
      <template v-slot:anomalyDescribeId="{ formData }">
        <el-form-item label="异常描述" prop="anomalyDescribeId" class="form_item_default">
          <el-select v-model="formData.anomalyDescribeId" @change="anomalyDescribeIdChange" class="form_input_default" filterable placeholder="请选择异常描述">
            <el-option v-for="(item,index) in describeData" :key="index" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
      </template>
    </ex_super_dialog_form>

    <ex_super_dialog_form ref="disposeDialog" v-bind="dispose_dialog"
      @afterSubmitSuccess="$refs['SuperTablePage'].reload()">
    </ex_super_dialog_form>
    <ex_super_dialog_form ref="checkDialog" v-bind="check_dialog" @afterSubmitSuccess="$refs['SuperTablePage'].reload()">
    </ex_super_dialog_form>
    <report_anomaly ref="report_anomaly" :orderTypeList="['TRANSPORT']"
    :formDisabled="['orderType']" :formHidden="['orderNo']"
    :extraModel="[
      {
              key: 'orderNo',
              label: 'label_order_code',
              render: (h, { data }) => {
                return h('ex_select_auto', {
                  class: 'form_input_default',
                  props: {
                    value: data.orderNo,
                    filterable: true,
                    url: '/tms-api/task/TmsBaseAnomalyRpc/getOrderByCustomerId.json',
                    urlParams: { customerId: data.customerId },
                    urlControl: (params) => {
                      return {
                        netStop: !params.customerId,
                        focusInnerData: [],
                      };
                    },
                    // listHandler:(list)=>_.unionBy(list, [iteratee=_.identity]),
                    dependentId: data.customerId,
                    option: { label: 'trackNumber', value: 'trackNumber' },
                  },
                  on: {
                    focus:()=>{
                       return data.customerId ? null : this.$message.warning(this.$tt('tip_please_select_first_customer'))
                    },
                    changeItem: (e) => {
                      this.$set(data, 'orderNo', e.trackNumber);
                      this.$set(data, 'anomalyBoxQty', e.boxQty);
                      this.$set(data, 'anomalySkuQty', e.skuQty);
                    },
                  },
                });
              },
            }
    ]"
    @afterSubmitSuccess="reload()" />
  </div>
</template>
<script>
import anomaly_desc_select from '@/component/common/anomaly_desc_select.vue'

import superTablePageFunction from '@/mixin/super-table-page-function';
import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'tms>anomaly_manage'
import report_anomaly from '@/component/dialog/report_anomaly.vue'

export default {
  title: '异常列表',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage,],
  components: { anomaly_desc_select, report_anomaly },
  data() {
    return {
      selection: [],
      option: {
        search: {
          model: [
            {
              key: "anomalyDescribeId",
              label: "label_anomaly_class", render: (h, { data }) => {
                return h(anomaly_desc_select, {
                  class: 'form_input_default',
                  props: {
                    classify: data.anomalyClassifyId,
                    describe: data.anomalyDescribeId,
                    classifyName: data.anomalyClassifyName,
                    describeName: data.anomalyDescribeName,
                  },
                  on: {
                    'classifyItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyClassifyId', e.id)
                      this.$set(data, 'anomalyClassifyName', e.name)
                    },
                    'describeItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyDescribeId', e.id)
                      this.$set(data, 'anomalyDescribeName', e.name)
                    },
                  }
                })
              }
            },
            { key: 'status', label: '状态', type: 'select', enum: 'AbnormalStatusEnum', },
            {
              key: 'anomalySourceMode', label: 'label_generation_method', type: 'select', enum: 'AbnormalSourceModeEnum',
            },
            {
              key: 'reportTimeBegin', label: 'label_start_report_time', type: 'date-picker',
              attrs: { clearable: false, type: "datetime", 'default-time': '00:00:00' },
            },
            {
              key: 'reportTimeEnd', label: 'label_end_report_time', type: 'date-picker',
              attrs: { clearable: false, type: "datetime", 'default-time': '23:59:59' },
            },

            {
              key: "reportUserName", label: "label_report_user",
            },
            {
              key: "customerName",
              label: "客户名称",
            },
            { key: 'orderNo', label: 'label_order_code', },
            { key: 'code', label: 'label_anomaly_code' },
          ],
        },
        actionExtra: [
          {
            label: 'label_report_exception',auth:"tms_anomaly_report", attrs: { icon: "el-icon-plus", type: 'primary' }, click: () => {
              // this['$refs']['formDialog'].show(null, { setData: true }, this.$tt('label_report_exception'))
              this['$refs']['report_anomaly'].showNew({
                data: {
                  orderType: 'TRANSPORT',
                },
                onlySetData: true,
              })
            }
          },
          {
            label: 'label_anomaly_confirm', attrs: { type: 'primary' }, click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))

              this.anomalysConfirm(this.selection)

            }
          },

          {
            label: "label_anomaly_close", click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))

              this.anomalysClose(this.selection)

            }
          },
          {
            label: "label_anomaly_restart", click: () => {
              if (_.isEmpty(this.selection)) return this.$message.error(this.$tt('tip_please_select_order'))

              this.anomalysRestart(this.selection)

            }
          },
          { label: 'label_export', attrs: { type: "primary" }, click: this.exportExcel },
        ],
        table: {
          url: "/tms-api/task/TmsBaseAnomalyRpc/selectByPage.json",
          model: [
            { type: 'selection', clickToggle: true, keyGroup: 'label_table_operate' },
            {
              key: 'code', label: 'label_anomaly_code', 'width': 140, 'show-overflow-tooltip': true,
            },
            {
              key: 'orderNo', label: 'label_order_code', 'width': 140, 'show-overflow-tooltip': true,
            },
            { key: 'customerName', label: 'label_customer_name', 'width': 100, 'show-overflow-tooltip': true, },
            {
              key: 'status', label: 'label_order_status', 'width': 100, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "AbnormalStatusEnum")
            },
            {
              key: 'orderType', label: 'label_order_type', 'width': 140, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "AbnormalOrderTypeEnum")
            },
            { key: 'boxQty', label: '箱数', 'min-width': 200, 'show-overflow-tooltip': true, },
            { key: 'skuQty', label: '件数', 'min-width': 200, 'show-overflow-tooltip': true, },
            { key: 'anomalyBoxQty', label: 'label_abnormal_box_count', 'width': 140, 'show-overflow-tooltip': true, },
            { key: 'anomalySkuQty', label: 'label_abnormal_piece_count', 'width': 140, 'show-overflow-tooltip': true, },
            { key: 'anomalyClassifyName', label: 'label_anomaly_class', 'width': 140, 'show-overflow-tooltip': true },
            { key: 'anomalyDescribeName', label: 'label_anomaly_desc', 'width': 100, 'show-overflow-tooltip': true, },
            { key: 'anomalySkuValue', label: '异常商品价值', 'width': 100, 'show-overflow-tooltip': true, },
            {
              key: 'anomalyCause', label: 'label_reason_abnormal', 'width': 100, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "AnomalyCauseEnum")
            },
            {
              key: 'anomalySourceMode', label: 'label_generation_method', 'width': 100, 'show-overflow-tooltip': true,
              formatter: (r, c, v, i) => this.$enumShow(v, "AbnormalSourceModeEnum")
            },
            { key: 'anomalyRestartCause', label: '异常重启原因', 'width': 100, 'show-overflow-tooltip': true, },
            { key: 'reportTime', label: 'label_report_time', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v), },
            { key: 'reportUserName', label: 'label_report_user', 'width': 100, 'show-overflow-tooltip': true, },
            { key: 'creator', label: '更新人', 'width': 100, 'show-overflow-tooltip': true, },
            { key: 'gmtModify', label: '更新时间', 'width': 100, 'show-overflow-tooltip': true, formatter: (r, c, v, i) => this.$dateFormat(v), },
            {
              type: 'operate', width: 160, operate: [

                {
                  type: 'more',
                  items: [
                    {
                      label: 'label_view_detail', click: (row) => {
                        this.$router.push({
                          path: '/page/tms/anomaly/anomaly_detail', query: { id: row.id, }
                        })
                      }
                    },
                    {
                      label: 'label_exception_handle', click: (row) => {
                        this['$refs']['disposeDialog'].show({ "anomalyId": row["id"] }, {}, this.$tt('label_exception_handle'))
                      }
                    },
                    {
                      label: 'label_check_feedback', click: (row) => {
                        this['$refs']['checkDialog'].show({ "anomalyId": row["id"] }, {}, this.$tt('label_check_feedback'))
                      }
                    },
                    {
                      label: 'label_anomaly_confirm', click: (row) => {
                        this.anomalysConfirm(row)
                      }
                    },
                    {
                      label: 'label_anomaly_close', click: (row) => {
                        this.anomalysClose(row)
                      }
                    },
                    {
                      label: 'label_anomaly_restart', click: (row) => {
                        this.anomalysRestart(row)
                      }
                    },
                  ]
                }
              ]
            }
          ],
        }
      },

      edit_dialog: {
        customClass: 'dialog_auto',

        submitUrl: "/tms-api/task/TmsBaseAnomalyRpc/save.json",
        detailUrl: "",
        form: {
          itemClass: "form_item_default",
          inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: { orderType: 'TRANSPORT' },
          model: [
            { header: "label_report_exception", },
            {
              key: "customerId",
              label: "label_customer",
              type: 'select',
              attrs: {
                storeData: true,
                url: "/tms-api/task/TmsBaseAnomalyRpc/getAllCustomer.json",
                option: { label: 'customerName', value: 'customerId' }
              },
              keyExtra: { customerCode: 'customerCode', customerName: 'customerName' },
              on: {
                change: e => this.getOrderByCustomerId(e)
              }
            },
            { slot: 'orderNo' },
            { key: 'anomalyCause', label: 'label_reason_abnormal', type: 'select', attrs: { enum: 'AnomalyCauseEnum' } },
            {
              key: "anomalyDescribeId",
              label: "label_anomaly_desc", render: (h, { data }) => {
                return h(anomaly_desc_select, {
                  class: 'form_input_default',
                  props: {
                    classify: data.anomalyClassifyId,
                    describe: data.anomalyDescribeId,
                    classifyName: data.anomalyClassifyName,
                    describeName: data.anomalyDescribeName,
                    processNodeList: this.processNodeList,
                  },
                  on: {
                    'classifyItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyClassifyId', e.id)
                      this.$set(data, 'anomalyClassifyName', e.name)
                    },
                    'describeItem': (e) => {
                      if (!e) e = { id: null, name: null }
                      this.$set(data, 'anomalyDescribeId', e.id)
                      this.$set(data, 'anomalyDescribeName', e.name)
                    },
                  }
                })
              }
            },
            {
              key: 'anomalyClassifyId',
              label: 'label_anomaly_class',
              type: 'select',
              attrs: {
                storeData: true,
                url: "/tms-api/task/TmsBaseAnomalyRpc/selectAnomalyClassify.json",
                option: { label: 'name', value: 'id' }
              },
              on: {
                change: e => {
                  // this.anomalyDescribeId = ''
                  this.$set(this['$refs']['formDialog'].$refs.form.formData, 'anomalyDescribeId', '')

                  this.selectByAnomalyClassifyId(e)
                }
              }
            },
            { slot: "anomalyDescribeId" },
            {
              key: 'anomalyOccurrenceDate', label: 'label_abnormal_happen_time', type: 'date-picker',
              attrs: { clearable: false, type: "date", },
            },
            // {
            //   key: 'orderType', label: 'label_order_type', formType: 'text',
            //   formatter: (r, c, v, i) => this.$enumShow(v, "AbnormalOrderTypeEnum")
            // },


            // { key: 'anomalyRemark', label: 'label_abnormal_remark', attrs: { maxlength: 50, 'show-word-limit': true }  },

            { key: 'anomalyBoxQty', label: 'label_abnormal_box_count', attrs: { maxlength: 9, 'show-word-limit': true } },
            { key: 'anomalySkuQty', label: 'label_abnormal_piece_count', attrs: { maxlength: 9, 'show-word-limit': true } },
            { key: 'anomalySkuValue', label: 'label_abnormal_sku_value', attrs: { maxlength: 9, 'show-word-limit': true } },

            {
              key: 'attachedDTOList', label: 'label_abnormal_attachment', type: 'upload-file', attrs: { limit: 3 },
              render: (h, { data }) => {
                return h('ex-upload-file', {
                  props: {
                    limit: 3,
                    value: data.attachedDTOList,
                    accept: '.jpg,.png,.jpeg'
                  },
                  on: {
                    input: (list) => {
                      this.$set(data, 'attachedDTOList', list.map(it => {
                        it.type = 'ABNORMAL'
                        return it
                      }))
                    }
                  }
                },)
              }

            },

          ],
          rules: {
            anomalyClassifyId: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            anomalyClassifyName: { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'customerId': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyDescribeId': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'orderType': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'orderNo': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyBoxQty': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },
            'anomalySkuQty': {
              required: true, trigger: 'blur',
              validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },

            // 'anomalySkuValue': {
            //   required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur',
            //   validator: (r, v, cb) => {
            //     if (_.isEmpty(v)) {
            //       cb(this.$tt('tip_can_no_empty'))
            //     } else if (!this.$reg.DigitNumber(v, 2, 9)) {
            //       cb(this.$tt("tip_check_decimal_digit_int", { digit: 2, int: 9 }))
            //     } else {
            //       cb()
            //     }
            //   }
            // },
            'anomalyCause': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'anomalyOccurrenceDate': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
          },
        }
      },

      dispose_dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/tms-api/task/TmsBaseAnomalyRpc/disposePC.json',
        detailUrl: "/tms-api/task/TmsBaseAnomalyRpc/toDispose.json",
        submitDataHandle: (data) => {
          return {
            "anomalyId": data.id,
            "anomalyCode": data.code,
            "disposeMode": data.disposeMode,
            "disposeResponsibleParty": data.disposeResponsibleParty,
            "disposeBoxQty": data.disposeBoxQty,
            "disposeSkuQty": data.disposeSkuQty,
            "isCompensation": data.isCompensation,
            "checkRemark": data.checkRemark,
            "compensationAmount": data.compensationAmount
          }
        },
        detailDataHandle: (data) => {
          data.disposeBoxQty = data.anomalyBoxQty
          data.disposeSkuQty = data.anomalySkuQty
          return data
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            { header: "label_exception_handle", },
            {
              key: "orderNo", label: "label_order_code", formType: 'text',
            },
            {
              key: "anomalyCause", label: "label_reason_abnormal", formType: 'text',
              formatter: (r, c, v, i) => this.$enumShow(v, "AnomalyCauseEnum")
            },
            {
              key: "anomalyClassifyName", label: "label_anomaly_class", formType: 'text',
            },
            {
              key: "anomalyDescribeName", label: "label_anomaly_desc", formType: 'text',
            },
            {
              key: "anomalyOccurrenceDate", label: "label_abnormal_happen_time", formType: 'text',
              formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            { key: 'anomalyBoxQty', label: 'label_abnormal_box_count', formType: 'text', },
            { key: 'anomalySkuQty', label: 'label_abnormal_piece_count', formType: 'text', },
            { key: 'anomalySkuValue', label: 'label_abnormal_sku_value', formType: 'text', },
            {
              key: 'reportUserName', label: 'label_report_user', formType: 'text',
            },
            {
              key: 'acceptUserName', label: 'label_accept_user', formType: 'text',
            },
            {
              key: "reportTime", label: "label_report_time", formType: 'text',
              formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            {
              key: "acceptTime", label: "label_accept_time", formType: 'text',
              formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            {
              key: 'checkUserName', label: 'label_check_user', formType: 'text',
            },
            {
              key: 'checkRemark', label: 'label_check_feedback', formType: 'text',
            },
            { key: 'disposeResponsibleParty', label: 'label_handler_determine_responsible', type: 'select', attrs: { enum: 'AbnormalResponsiblePartyEnum' } },
            { key: 'disposeMode', label: 'label_do_with_method', type: 'select', attrs: { enum: 'AbnormalDisposeModeEnum' } },
            { key: 'disposeBoxQty', label: 'label_handler_box_count', },
            { key: 'disposeSkuQty', label: 'label_handler_piece_count' },
            { key: 'isCompensation', label: 'label_is_compensation', type: 'select', attrs: { enum: 'YesOrNoEnum' } },
            { key: 'compensationAmount', label: 'label_compensation_money', if: (data) => data.isCompensation == 'Y', },
          ],
          rules: {
            'disposeResponsibleParty': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

            'disposeMode': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'isCompensation': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'disposeBoxQty': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },
            'disposeSkuQty': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (_.isEmpty(v)) {
                  cb(this.$tt('tip_can_no_empty'))
                } else if (!this.$reg.PureNumber(v)) {
                  cb(this.$tt("tip_only_positive_pure_decimal"))
                } else {
                  cb()
                }
              }
            },

            'compensationAmount': {
              required: true, trigger: 'blur', validator: (r, v, cb) => {
                if (r.isCompensation == 'Y') {
                  cb()
                } else if (!this.$reg.DigitNumber(v, 2, 9)) {
                  cb(this.$tt("tip_check_decimal_digit_int", { digit: 2, int: 9 }))
                } else {
                  cb()
                }
              }
            },

          },
        }
      },
      check_dialog: {
        customClass: 'dialog_auto',
        submitUrl: '/tms-api/task/TmsBaseAnomalyRpc/check.json',
        detailUrl: "/tms-api/task/TmsBaseAnomalyRpc/toCheck.json",
        submitDataHandle: (data) => {
          return {
            anomalyId: data.id,
            anomalyCode: data.code,
            checkResponsibleParty: data.checkResponsibleParty,
            checkRemark: data.checkRemark,
            attachedDTOList: data.attachedDTOList
          }
        },
        form: {
          itemClass: "form_item_default", inputClass: "form_input_default",
          formClass: "form_default_col2 flex_row_wrap",
          default: {},
          model: [
            { header: "label_check_feedback", },
            {
              key: "orderNo", label: "label_order_code", formType: 'text',
            },
            {
              key: "anomalyCause", label: "label_reason_abnormal", formType: 'text',
              formatter: (r, c, v, i) => this.$enumShow(v, "AnomalyCauseEnum")
            },
            {
              key: "anomalyClassifyName", label: "label_anomaly_class", formType: 'text',
            },
            {
              key: "anomalyDescribeName", label: "label_anomaly_desc", formType: 'text',
            },
            {
              key: "anomalyOccurrenceDate", label: "label_abnormal_happen_time", formType: 'text',
              formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            { key: 'anomalyBoxQty', label: 'label_abnormal_box_count', formType: 'text', },
            { key: 'anomalySkuQty', label: 'label_abnormal_piece_count', formType: 'text', },
            {
              key: 'reportUserName', label: 'label_report_user', formType: 'text',
            },
            {
              key: "reportTime", label: "label_report_time", formType: 'text',
              formatter: (r, c, v, i) => this.$dateFormat(v)
            },
            {
              key: 'acceptUserName', label: 'label_accept_user', formType: 'text',
            },
            { key: 'checkResponsibleParty', label: 'label_check_determine_responsible', type: 'select', attrs: { enum: 'AbnormalResponsiblePartyEnum' } },
            {
              key: 'attachedDTOList', label: 'label_check_feedback_attachment', type: 'upload-file', attrs: { limit: 3 },
              render: (h, { data }) => {
                return h('ex-upload-file', {
                  props: {
                    limit: 3,
                    value: data.attachedDTOList,
                    accept: '.jpg,.png,.jpeg'
                  },
                  on: {
                    input: (list) => {
                      this.$set(data, 'attachedDTOList', list.map(it => {
                        it.type = 'CHECK'
                        return it
                      }))
                    }
                  }
                },)
              }
            },
            {
              key: 'checkRemark', label: 'label_check_remarck', attrs: {
                type: 'textarea'
              }
            },
          ],
          rules: {
            'anomalyAttachedList': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'checkResponsibleParty': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },
            'checkRemark': { required: true, message: this.$tt('tip_can_no_empty'), trigger: 'blur' },

          },
        }
      },
      orderNoData: [],
      describeData: []
    };
  },
  methods: {
    anomalysConfirm(rows) {
      if (!Array.isArray(rows)) {
        rows = [rows]
      }
      this.$confirm(this.$tt('tip_xxx_will_comfirm_count_abnormal', { count: rows.length }), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/tms-api/task/TmsBaseAnomalyRpc/confirm.json",
          method: 'post',
          type: "json",
          loading: true,
          data: {
            anomalyIds: rows.map(it => it.id)
          },
          success: (res) => {
            this.$message({
              showClose: true,
              message: this.$tt('tip_submit_success'),
              type: 'success'
            })
            this.reload()
          }
        })
      }).catch(() => {
      });
    },
    anomalysClose(rows) {
      if (!Array.isArray(rows)) {
        rows = [rows]
      }
      this.$confirm(this.$tt('tip_xxx_will_close_count_abnormal', { count: rows.length }), this.$tt('label_tip'), {
        type: 'warning'
      }).then(() => {
        this.$ajax({
          url: "/tms-api/task/TmsBaseAnomalyRpc/close.json",
          method: 'post', type: "json",
          loading: true,
          data: {
            anomalyIds: rows.map(it => it.id)
          },
          success: (res) => {
            this.$message({
              showClose: true,
              message: this.$tt('tip_submit_success'),
              type: 'success'
            })
            this.reload()
          }
        })
      }).catch(() => {
      });

    },

    anomalysRestart(rows) {
      if (!Array.isArray(rows)) {
        rows = [rows]
      }
      this.$prompt(this.$tt('tip_xxx_will_restart_count_abnormal_for_reason', { count: rows.length }), this.$tt('label_tip'), {
        inputPattern: /\S/,
        inputErrorMessage: '请输入重启原因'
      }).then(({ value }) => {
        this.$ajax({
          url: "/tms-api/task/TmsBaseAnomalyRpc/restart.json",
          method: 'post', type: "json",
          loading: true,
          data: {
            anomalyIds: rows.map(it => it.id),
            anomalyRestartCause: value
          },
          success: (res) => {
            this.$message({
              showClose: true,
              message: this.$tt('tip_submit_success'),
              type: 'success'
            })
            this.reload()
          }
        })
      }).catch(() => {
      });

    },
    // 获取物流订单
    getOrderByCustomerId(customerId) {
      this.$ajax({
        url: `/tms-api/task/TmsBaseAnomalyRpc/getOrderByCustomerId.json`,
        method: 'post',
        type: 'formData',
        data: {
          customerId
        },
        loading: true,
        success: (res) => {
          this.orderNoData = res.data.rows
        }
      })
    },
    // 获取异常描述
    selectByAnomalyClassifyId(anomalyClassifyId) {
      this.$ajax({
        url: `/tms-api/task/TmsBaseAnomalyRpc/selectByAnomalyClassifyId.json`,
        method: 'get',
        data: {
          anomalyClassifyId
        },
        success: (res) => {
          this.describeData = res.data.rows
        }
      })
    },
    exportExcel() {
      this.$downloadFile({
        loading: true,
        type: 'json',
        url: '/tms-api/task/TmsBaseAnomalyRpc/exportExcel.json',
        data: {
          anomalyIds: this.selection.map(it => it.id),
          ...this.getSuperTablePage().getSearchFormData()
        },
      })
    },
    anomalyDescribeIdChange(e){
      if(e){
       const obj=  this.describeData.find(item=>item.id===e)
       this.$set(this['$refs']['formDialog'].$refs.form.formData,'anomalyClassifyName',obj.anomalyClassifyName)
       this.$set(this['$refs']['formDialog'].$refs.form.formData,'anomalyDescribeName',obj.name)
      }
    },
    orderNoChange(e) {
      if (e) {
        console.log(e, this.orderNoData)
        const obj = this.orderNoData.find(item => item.trackNumber === e)
        this.$set(this['$refs']['formDialog'].$refs.form.formData, 'boxQty', obj.boxQty)
        this.$set(this['$refs']['formDialog'].$refs.form.formData, 'skuQty', obj.skuQty)


      }
    }
  }
};

</script>
<style></style>
